package com.cnhis.cloudhealth.clinical.hosdoctor.doctororderreset.bo;

import com.cnhis.cloudhealth.clinical.hosdoctor.doctororderreset.dao.DoctororderresetDao;
import com.cnhis.cloudhealth.commons.Mappers.ModelVo;
import com.cnhis.cloudhealth.commons.newid.GetNewId;
import com.cnhis.cloudhealth.commons.utils.DateUtils;
import com.cnhis.cloudhealth.commons.utils.JsonUtil;
import com.cnhis.cloudhealth.commons.utils.StaticKeys;
import com.cnhis.cloudhealth.commons.utils.StringUtils;
import org.apache.commons.collections.MapUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.*;

@Service
public class DoctororderresetBo {
	@Resource
	private DoctororderresetDao doctororderresetDao;
	@Autowired
	private GetNewId getNewId;

	private List<Map<String,String>> changeToString(List<?> list){
		List<Map<String,String>> resultList = new ArrayList<Map<String,String>>();
		for(Object o:list){
			if(o instanceof Map){
				Map<String,Object> pmap = (Map<String,Object>)o;
				Map<String,String> smap = new HashMap<String,String>();
				Iterator<Map.Entry<String, Object>> it = pmap.entrySet().iterator();
				while (it.hasNext()) {
					Map.Entry<String, Object> entry = it.next();
					String str = String.valueOf(entry.getValue());
					smap.put(entry.getKey(),str);
				}
				resultList.add(smap);
			}
		}
		return resultList;
	}

	private ModelVo packModelVo(String nid, Map map){
		ModelVo mo = new ModelVo();
		List<?> list = null;
		try {
			list = doctororderresetDao.queryForList(nid,map);
			list = changeToString(list);
		} catch (Exception e) {
			mo.setResult(StaticKeys.OH_FALSE);
			mo.setResultMsg("数据操作异常！");
			e.printStackTrace();
		}
		if(list!=null&&list.size()>0) {
			mo.setList(list);
			mo.setResult(StaticKeys.OH_SUCCESS);
			mo.setTotal(list.size());
			mo.setRows(list);
		}
		return mo;
	}
	public ModelVo selectOrderresetList(Map<String,Object> map){return packModelVo("Doctororderreset.7712",map);}
	public ModelVo selectExeDepList(Map<String,Object> map){return packModelVo("Doctororderreset.1132",map);}
	public ModelVo executeOrderreset(Map<String,Object> map)throws Exception{
		String lxml = MapUtils.getString(map,"lxml","");
		if(StringUtils.isBlank(lxml)){
			return new ModelVo(StaticKeys.OH_FALSE, "参数为空，请检查参数！");
		}
		//将Json数据装换为list
		List<Map<String,Object>> lxmlList = JsonUtil.getList(lxml);
		//根据医嘱记录ID组成临时表TmpVAFzt
		List<Map<String,Object>> TmpVAFzt = doctororderresetDao.queryForList("Doctororderreset.resetorder_001",lxmlList);
		if(TmpVAFzt==null||TmpVAFzt.size()==0){
			return new ModelVo(StaticKeys.OH_FALSE, "请选择重整医嘱明细内容！");
		}
		map.put("adate",new Date());
		Long BBX01 = (Long)doctororderresetDao.queryToObject("Doctororderreset.resetorder_002",map);
		if(BBX01==null||BBX01==0){
			return new ModelVo(StaticKeys.OH_FALSE, "请先到诊疗项目管理中维护[重整医嘱]项目.");
		}
		map.put("BBX01",BBX01);
		Integer BCE01A = MapUtils.getInteger(map,"BCE01A",-1);
		if(BCE01A<0){
			return new ModelVo(StaticKeys.OH_FALSE, "请指定开嘱医师.");
		}
		Integer BCE01C = MapUtils.getInteger(map,"BCE01C",0);
		String BCE03 = "";
		if(BCE01C>0){
			BCE03 = (String)doctororderresetDao.queryToObject("Doctororderreset.resetorder_003",map);
		}else{
			BCE03 = "";
		}
		map.put("BCE03",BCE03);
		List<Long> nidList = getNewId.nextId(4);
		map.put("cbm2id",nidList.get(0));
		map.put("vaf2id",nidList.get(1));
		map.put("vagid",nidList.get(2));
		map.put("vbdid",nidList.get(3));
		Long vaf01 = (Long)doctororderresetDao.queryToObject("Doctororderreset.resetorder_004",map);
		if(vaf01!=null){
			return new ModelVo(StaticKeys.OH_FALSE, "有医嘱状态已发生变化，请返回刷新.");
		}
		//插入医嘱单CBM2
		doctororderresetDao.insert("Doctororderreset.resetorder_005",map);
		//插入医嘱记录VAF2
		doctororderresetDao.insert("Doctororderreset.resetorder_006",map);
		//更新医嘱单VAF2
		doctororderresetDao.update("Doctororderreset.resetorder_007",map);
		//插入住院病人医嘱计价VBD2
		doctororderresetDao.insert("Doctororderreset.resetorder_008",map);
		//更新病人医嘱提醒VBZ1
		doctororderresetDao.update("Doctororderreset.resetorder_009",map);
		//插入病人医嘱状态VBG1
		doctororderresetDao.insert("Doctororderreset.resetorder_010",map);
		return  new ModelVo(StaticKeys.OH_SUCCESS, "重整医嘱成功！");
	}
	/* 医嘱字段调整Nurse_Advice_Items_Update*/
	public ModelVo medicalOrderModify(Map<String,Object> map)throws Exception{
		//0:调整执行科室  1:调整附加执行科室  2:调整停嘱时间 3:调整描嘱 4:调整校对时间 6:调整拆零标识 7:调整长嘱终止时间  9:调整医嘱开始时间 10:调整确认停嘱时间
		Integer lType = MapUtils.getInteger(map,"lType",0);
		Integer lBCK01 = MapUtils.getInteger(map,"lBCK01",0);
		String lBDA01 = MapUtils.getString(map,"lBDA01","");
		String lStopTime = MapUtils.getString(map,"lStopTime");
		String rtxt = "";
		if(lType==9 || lType==4 || lType==5 || lType==10){
			String vaf01s = MapUtils.getString(map,"vaf01s","");
			String[] arr = vaf01s.split(",");
			if(lType==9) {
				for(String vid:arr) {
					map.put("lVAF01", Long.parseLong(vid));
					Map<String, Object> vafMap = (Map<String, Object>) doctororderresetDao.queryToObject("Doctororderreset.modifyorder_001", map);
					Long lVAF01A = MapUtils.getLong(vafMap, "vaf01a");
					Integer lVAF10 = MapUtils.getInteger(vafMap, "vaf10");
					Integer lVAF11 = MapUtils.getInteger(vafMap, "vaf11");
					Integer lVAF59 = MapUtils.getInteger(vafMap, "vaf59");
					String vaf22 = MapUtils.getString(vafMap, "vaf22");
					Long lCBM01 = MapUtils.getLong(vafMap, "cbm01");
					map.put("lStopTime", lStopTime);
					map.put("lVAF01A", lVAF01A);
					map.put("lVAF10", lVAF10);
					map.put("lVAF11", lVAF11);
					map.put("lVAF59", lVAF59);
					map.put("lCBM01", lCBM01);
					Integer cn3 = (Integer) doctororderresetDao.queryToObject("Doctororderreset.modifyorder_028", map);
					if (cn3 == 0) {
						return new ModelVo(StaticKeys.OH_FALSE, vaf22 + " 已经校队或者发送，不能调整开始时间,请重新查询医嘱!");
					}

					doctororderresetDao.update("Doctororderreset.modifyorder_029", map);
					rtxt = "调整医嘱开始时间";
					Long lVBG01 = getNewId.nextId();
					map.put("lVBG01", lVBG01);
					map.put("ptxt", rtxt + lStopTime);
					doctororderresetDao.insert("Doctororderreset.modifyorder_017", map);
				}
			}else if(lType==4){
				for(String vid:arr) {
					map.put("lVAF01", Long.parseLong(vid));
					Map<String, Object> vafMap = (Map<String, Object>) doctororderresetDao.queryToObject("Doctororderreset.modifyorder_001", map);
					Long lVAF01A = MapUtils.getLong(vafMap, "vaf01a");
					Integer lVAF10 = MapUtils.getInteger(vafMap, "vaf10");
					Integer lVAF11 = MapUtils.getInteger(vafMap, "vaf11");
					Integer lVAF59 = MapUtils.getInteger(vafMap, "vaf59");
					String vaf22 = MapUtils.getString(vafMap, "vaf22");
					Long lCBM01 = MapUtils.getLong(vafMap, "cbm01");
					map.put("lStopTime", lStopTime);
					map.put("lVAF01A", lVAF01A);
					map.put("lVAF10", lVAF10);
					map.put("lVAF11", lVAF11);
					map.put("lVAF59", lVAF59);
					map.put("lCBM01", lCBM01);
					Integer cn4 = (Integer) doctororderresetDao.queryToObject("Doctororderreset.modifyorder_004", map);
					if (cn4 > 0) {
						return new ModelVo(StaticKeys.OH_FALSE, vaf22 + " 校对时间不能小于医嘱开始时间。");
					}
					Integer cn5 = (Integer) doctororderresetDao.queryToObject("Doctororderreset.modifyorder_0042", map);
					if (cn5 > 0) {
						return new ModelVo(StaticKeys.OH_FALSE, vaf22 + " 校对时间不能大于医嘱停止时间。");
					}
					Integer cn6 = (Integer) doctororderresetDao.queryToObject("Doctororderreset.modifyorder_0043", map);
					if (cn6 > 0) {
						return new ModelVo(StaticKeys.OH_FALSE, vaf22 + " 校对时间不能大于医嘱发送时间。");
					}
					rtxt = "调整医嘱校对时间";
					doctororderresetDao.update("Doctororderreset.modifyorder_025", map);
					Long lVBG01 = getNewId.nextId();
					map.put("lVBG01", lVBG01);
					map.put("ptxt", rtxt + lStopTime);
					doctororderresetDao.insert("Doctororderreset.modifyorder_017", map);
				}
			}else if(lType==5){
				for(String vid:arr) {
					map.put("lVAF01", Long.parseLong(vid));
					Map<String, Object> vafMap = (Map<String, Object>) doctororderresetDao.queryToObject("Doctororderreset.modifyorder_001", map);
					Long lVAF01A = MapUtils.getLong(vafMap, "vaf01a");
					Integer lVAF10 = MapUtils.getInteger(vafMap, "vaf10");
					Integer lVAF11 = MapUtils.getInteger(vafMap, "vaf11");
					Integer lVAF59 = MapUtils.getInteger(vafMap, "vaf59");
					String vaf22 = MapUtils.getString(vafMap, "vaf22");
					Long lCBM01 = MapUtils.getLong(vafMap, "cbm01");
					map.put("lStopTime", lStopTime);
					map.put("lVAF01A", lVAF01A);
					map.put("lVAF10", lVAF10);
					map.put("lVAF11", lVAF11);
					map.put("lVAF59", lVAF59);
					map.put("lCBM01", lCBM01);
					Integer cn4 = (Integer) doctororderresetDao.queryToObject("Doctororderreset.modifyorder_0041", map);
					if (cn4 > 0) {
						return new ModelVo(StaticKeys.OH_FALSE, vaf22 + "发送时间不能小于医嘱校对时间。");
					}
					Integer cn5 = (Integer) doctororderresetDao.queryToObject("Doctororderreset.modifyorder_00411", map);
					if (cn5 > 0) {
						return new ModelVo(StaticKeys.OH_FALSE, vaf22 + "费用已经上传医保,不能修改发送时间,请联系管理员。");
					}
					rtxt = "调整医嘱发送时间";
					doctororderresetDao.update("Doctororderreset.modifyorder_0251", map);
					Long lVBG01 = getNewId.nextId();
					map.put("lVBG01", lVBG01);
					map.put("ptxt", rtxt + lStopTime);
					doctororderresetDao.insert("Doctororderreset.modifyorder_017", map);
				}
			}else if(lType==10){
				for(String vid:arr) {
					map.put("lVAF01", Long.parseLong(vid));
					Map<String, Object> vafMap = (Map<String, Object>) doctororderresetDao.queryToObject("Doctororderreset.modifyorder_001", map);
					Long lVAF01A = MapUtils.getLong(vafMap, "vaf01a");
					Integer lVAF10 = MapUtils.getInteger(vafMap, "vaf10");
					Integer lVAF11 = MapUtils.getInteger(vafMap, "vaf11");
					Integer lVAF59 = MapUtils.getInteger(vafMap, "vaf59");
					String vaf22 = MapUtils.getString(vafMap, "vaf22");
					Long lCBM01 = MapUtils.getLong(vafMap, "cbm01");
					map.put("lStopTime", lStopTime);
					map.put("lVAF01A", lVAF01A);
					map.put("lVAF10", lVAF10);
					map.put("lVAF11", lVAF11);
					map.put("lVAF59", lVAF59);
					map.put("lCBM01", lCBM01);
					Integer cn4 = (Integer) doctororderresetDao.queryToObject("Doctororderreset.modifyorder_00410", map);
					if (cn4 > 0) {
						return new ModelVo(StaticKeys.OH_FALSE, vaf22 + "确认停嘱时间不能小于医嘱停嘱时间。");
					}
					Integer cn5 = (Integer) doctororderresetDao.queryToObject("Doctororderreset.modifyorder_004110", map);
					if (cn5 > 0) {
						return new ModelVo(StaticKeys.OH_FALSE, vaf22 + "只能对已经确认停嘱的医嘱进行调整!");
					}
					rtxt = "调整医嘱确认停嘱时间";
					doctororderresetDao.update("Doctororderreset.modifyorder_02510", map);
					Long lVBG01 = getNewId.nextId();
					map.put("lVBG01", lVBG01);
					map.put("ptxt", rtxt + lStopTime);
					doctororderresetDao.insert("Doctororderreset.modifyorder_017", map);
				}
			}
		}else{
			Map<String, Object> vafMap = (Map<String, Object>) doctororderresetDao.queryToObject("Doctororderreset.modifyorder_001", map);
			Long lVAF01A = MapUtils.getLong(vafMap,"vaf01a");
			Integer lVAF10 = MapUtils.getInteger(vafMap,"vaf10");
			Integer lVAF11 = MapUtils.getInteger(vafMap,"vaf11");
			Integer lVAF59 = MapUtils.getInteger(vafMap,"vaf59");
			map.put("lStopTime", lStopTime);
			map.put("lVAF01A",lVAF01A);
			map.put("lVAF10",lVAF10);
			map.put("lVAF11",lVAF11);
			map.put("lVAF59",lVAF59);

			if(lType==0) {
				if(lBCK01==0){
					return  new ModelVo(StaticKeys.OH_FALSE, "请先选择执行科室！");
				}
				Integer cn = (Integer)doctororderresetDao.queryToObject("Doctororderreset.modifyorder_002", map);
				if((lVAF11==2&&lVAF10>3)||(lVAF11==1&&((lVAF10>3)||(lVAF10==3&&cn>0)))){
					return  new ModelVo(StaticKeys.OH_FALSE, "只能对未执行医嘱的执行科室进行调整！");
				}
				if("1".equals(lBDA01)||"2".equals(lBDA01)){
//				doctororderresetDao.update("Doctororderreset.modifyorder_008", map);
					doctororderresetDao.update("Doctororderreset.modifyorder_009", map);
					doctororderresetDao.update("Doctororderreset.modifyorder_010", map);
				}else if("8".equals(lBDA01)){
					doctororderresetDao.update("Doctororderreset.modifyorder_011", map);
					doctororderresetDao.update("Doctororderreset.modifyorder_012", map);
				}else if("S".equals(lBDA01)||"E".equals(lBDA01)){
					doctororderresetDao.update("Doctororderreset.modifyorder_013", map);
					doctororderresetDao.update("Doctororderreset.modifyorder_014", map);
				}else{
					doctororderresetDao.update("Doctororderreset.modifyorder_015", map);
					doctororderresetDao.update("Doctororderreset.modifyorder_016", map);
				}
				Long lVBG01 = getNewId.nextId();
				rtxt = "调整执行科室";
				map.put("ptxt",rtxt);
				map.put("lVBG01",lVBG01);
				doctororderresetDao.insert("Doctororderreset.modifyorder_017", map);
			}else if(lType==1){
				if(lBCK01==0){
					return  new ModelVo(StaticKeys.OH_FALSE, "请先选择附加执行科室！");
				}
				Integer cn2 = (Integer)doctororderresetDao.queryToObject("Doctororderreset.modifyorder_002", map);
				if((lVAF11==2&&lVAF10>3)||(lVAF11==1&&((lVAF10>3)||(lVAF10==3&&cn2>0)))){
					return  new ModelVo(StaticKeys.OH_FALSE, "只能对未执行医嘱的附加执行科室进行调整！");
				}
				if("1".equals(lBDA01)||"2".equals(lBDA01)||"T".equals(lBDA01)){
					doctororderresetDao.update("Doctororderreset.modifyorder_008", map);
//				doctororderresetDao.update("Doctororderreset.modifyorder_009", map);
					doctororderresetDao.update("Doctororderreset.modifyorder_018", map);
				}else if("8".equals(lBDA01)){
//				doctororderresetDao.update("Doctororderreset.modifyorder_015", map);
					doctororderresetDao.update("Doctororderreset.modifyorder_019", map);
					doctororderresetDao.update("Doctororderreset.modifyorder_020", map);
				}else if("S".equals(lBDA01)){
					doctororderresetDao.update("Doctororderreset.modifyorder_021", map);
					doctororderresetDao.update("Doctororderreset.modifyorder_022", map);
				}
				Long lVBG01 = getNewId.nextId();
				rtxt = "调整附加执行科室";
				map.put("ptxt",rtxt);
				map.put("lVBG01",lVBG01);
				doctororderresetDao.insert("Doctororderreset.modifyorder_017", map);
			}else if(lType==2){
				Integer cn3 = (Integer)doctororderresetDao.queryToObject("Doctororderreset.modifyorder_003", map);
				if(cn3==0){
					return  new ModelVo(StaticKeys.OH_FALSE, "医嘱还没停嘱，不能调整停嘱时间。");
				}
				Integer cn4 = (Integer)doctororderresetDao.queryToObject("Doctororderreset.modifyorder_004", map);
				if(cn4>0){
					return  new ModelVo(StaticKeys.OH_FALSE, "停嘱时间不能小于医嘱开始时间。");
				}
				doctororderresetDao.update("Doctororderreset.modifyorder_023", map);

				rtxt = "调整医嘱停止时间";
				Long lVBG01 = getNewId.nextId();
				map.put("lVBG01",lVBG01);
				map.put("ptxt",rtxt+lStopTime);
				doctororderresetDao.insert("Doctororderreset.modifyorder_017", map);
			}else if(lType==3){	//调整描嘱
				Integer cn5 = (Integer)doctororderresetDao.queryToObject("Doctororderreset.modifyorder_005", map);
				if(cn5>0){
					return  new ModelVo(StaticKeys.OH_FALSE, "只能调整描述性医嘱的执行单类型。");
				}
				if(lBCK01<-1&&lBCK01>9){
					return  new ModelVo(StaticKeys.OH_FALSE, "请先选择执行单类型。");
				}
				Integer cn6 = (Integer)doctororderresetDao.queryToObject("Doctororderreset.modifyorder_006", map);
				if(cn6>0){
					return  new ModelVo(StaticKeys.OH_FALSE, "此描嘱已打印执行单，不能在进行调整！");
				}
				rtxt = "调整描嘱执行单类型";
				doctororderresetDao.update("Doctororderreset.modifyorder_024", map);
				Long lVBG01 = getNewId.nextId();
				map.put("lVBG01",lVBG01);
				map.put("ptxt",rtxt);
				doctororderresetDao.insert("Doctororderreset.modifyorder_017", map);
			}
			else if(lType==4){	//校对时间
//			Integer cn7 = (Integer)doctororderresetDao.queryToObject("Doctororderreset.modifyorder_007", map);
//			if(cn7==0){
//				return  new ModelVo(StaticKeys.OH_FALSE, "医嘱还没校对，不能调整校对时间！");
//			}
				Integer cn4 = (Integer)doctororderresetDao.queryToObject("Doctororderreset.modifyorder_004", map);
				if(cn4>0){
					return  new ModelVo(StaticKeys.OH_FALSE, "校对时间不能小于医嘱开始时间。");
				}
				rtxt = "调整医嘱校对时间";
				doctororderresetDao.update("Doctororderreset.modifyorder_025", map);
				Long lVBG01 = getNewId.nextId();
				map.put("lVBG01",lVBG01);
				map.put("ptxt",rtxt+lStopTime);
				doctororderresetDao.insert("Doctororderreset.modifyorder_017", map);
			}else if(lType==5){	//发送时间
//			Integer cn7 = (Integer)doctororderresetDao.queryToObject("Doctororderreset.modifyorder_0071", map);
//			if(cn7==0){
//				return  new ModelVo(StaticKeys.OH_FALSE, "医嘱还没发送，不能调整发送时间！");
//			}
				Integer cn4 = (Integer)doctororderresetDao.queryToObject("Doctororderreset.modifyorder_0041", map);
				if(cn4>0){
					return  new ModelVo(StaticKeys.OH_FALSE, "发送时间不能小于医嘱校对时间。");
				}
				rtxt = "调整医嘱发送时间";
				doctororderresetDao.update("Doctororderreset.modifyorder_0251", map);
				Long lVBG01 = getNewId.nextId();
				map.put("lVBG01",lVBG01);
				map.put("ptxt",rtxt+lStopTime);
				doctororderresetDao.insert("Doctororderreset.modifyorder_017", map);
			}
			else if(lType==6){
				doctororderresetDao.update("Doctororderreset.modifyorder_026", map);
				Long lVBG01 = getNewId.nextId();
				map.put("lVBG01",lVBG01);
				rtxt = "调整药品医嘱拆零标识";
				map.put("ptxt",rtxt+lBCK01);
				doctororderresetDao.insert("Doctororderreset.modifyorder_017", map);
			}else if(lType==7){
				doctororderresetDao.update("Doctororderreset.modifyorder_027", map);
				rtxt = "调整长嘱终止时间";
				Long lVBG01 = getNewId.nextId();
				map.put("lVBG01",lVBG01);
				map.put("ptxt",rtxt+lStopTime);
				doctororderresetDao.insert("Doctororderreset.modifyorder_017", map);
			}
		}

		return  new ModelVo(StaticKeys.OH_SUCCESS, rtxt+"成功！");
	}

	public ModelVo selectFeerecord(Map<String,Object> map){
		Integer lMode = MapUtils.getInteger(map,"lMode");
		if(lMode<=1){
			return packModelVo("Doctororderreset.7273_001",map);
		}else{
			return packModelVo("Doctororderreset.7273_002",map);
		}
	}

	public ModelVo feedetailUpdate(Map<String,Object> map)throws Exception{
		Integer lSign = MapUtils.getInteger(map,"lSign",0);
		String VAJ46 = MapUtils.getString(map,"VAJ46");
		Date VAJ46_D = (Date)map.get("VAJ46");
		Long VAJ01 = MapUtils.getLong(map,"VAJ01");
		String VAJ39 = MapUtils.getString(map,"VAJ39");
		Integer Mode = MapUtils.getInteger(map,"Mode");
		Integer cn = (Integer)doctororderresetDao.queryToObject("Doctororderreset.vajupdate_001", map);
		if(cn==0){
			return  new ModelVo(StaticKeys.OH_FALSE, "病人不是在院状态，不能调整费用信息.");
		}
		Integer cn2 = (Integer)doctororderresetDao.queryToObject("Doctororderreset.vajupdate_002", map);
		if (lSign==0&&cn2>0) {
			return  new ModelVo(StaticKeys.OH_FALSE, "业务时间不能小于病人入院时间.");
		}
		if(lSign==0&&VAJ46_D!=null&&VAJ46_D.after(new Date())){
			return  new ModelVo(StaticKeys.OH_FALSE, "业务时间不能大于当前系统时间.");
		}
		if(VAJ01<1){
			return  new ModelVo(StaticKeys.OH_FALSE, "请选择费用记录.");
		}
		Integer cn3 = (Integer)doctororderresetDao.queryToObject("Doctororderreset.vajupdate_003", map);
		if(lSign==2&&cn3>0){
			return  new ModelVo(StaticKeys.OH_FALSE, "医嘱已发送停止，不能在调整..");
		}
		Map<String,Object> vajMap = (Map<String,Object>)doctororderresetDao.queryToObject("Doctororderreset.vajupdate_004", map);
		String oldVAJ39  = MapUtils.getString(vajMap,"vaj39","");
		String oldVAJ46 = MapUtils.getString(vajMap,"vaj46","");
		String VAI01 = MapUtils.getString(vajMap,"vai01","");

		String ZAE06 = "";
		String ZAE07 = "";
		String Fname = "";
		String FTab = "";
		String ZAE08 = "";

		if(lSign==1){
			ZAE06 = oldVAJ39;
			ZAE07 = VAJ39;
			Fname = "VAJ39";
			FTab = "VAJ2";
			ZAE08 = "调整费用标识";
			doctororderresetDao.update("Doctororderreset.vajupdate_011", map);
		}else if(lSign==0){
			FTab = "VAJ1";
			if(Mode==0){
				ZAE06 = oldVAJ46;
				ZAE07 = VAJ46;
				Fname = "VAJ46";
				ZAE08 = "调整费用业务时间";
				doctororderresetDao.update("Doctororderreset.vajupdate_007", map);
			}else if(Mode==1){
				ZAE06 = String.valueOf(oldVAJ46);
				ZAE07 = String.valueOf(VAJ46);
				Fname = "VAJ46";
				ZAE08 = "调整单据费用业务时间";
				VAJ01 = Long.valueOf(VAI01);
				map.put("VAJ01",VAJ01);
				doctororderresetDao.update("Doctororderreset.vajupdate_008", map);
				doctororderresetDao.update("Doctororderreset.vajupdate_009", map);
			}

		}else if(lSign==2){
			Integer VAF31 = (Integer)doctororderresetDao.queryToObject("Doctororderreset.vajupdate_005", map);
			ZAE06 = String.valueOf(VAF31);
			ZAE07 = String.valueOf(VAJ39);
			Fname = "VAF31";
			FTab = "VAF2";
			ZAE08 = "调整医嘱计价性质";
			doctororderresetDao.update("Doctororderreset.vajupdate_011", map);
		}
		map.put("ZAE06",ZAE06);
		map.put("ZAE07",ZAE07);
		map.put("Fname",Fname);
		map.put("FTab",FTab);
		map.put("ZAE08",ZAE08);
		Long lZAE01 = getNewId.nextId();
		map.put("lZAE01",lZAE01);
		doctororderresetDao.insert("Doctororderreset.vajupdate_006", map);

		return  new ModelVo(StaticKeys.OH_SUCCESS, "更新成功");
	}

}
